'
'Copyright (c) 2007-2012 Benton Stark, Starksoft LLC (http://www.starksoft.com) 
'
'Permission is hereby granted, free of charge, to any person obtaining a copy
'of this software and associated documentation files (the "Software"), to deal
'in the Software without restriction, including without limitation the rights
'to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
'copies of the Software, and to permit persons to whom the Software is
'furnished to do so, subject to the following conditions:
'
'The above copyright notice and this permission notice shall be included in
'all copies or substantial portions of the Software.
'
'THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
'IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
'FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
'AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
'LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
'OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
'THE SOFTWARE.
'



Namespace FTP
    ''' <summary>
    ''' Event arguments to facilitate the transfer progress event.
    ''' </summary>
    Public Class TransferProgressEventArgs
        Inherits EventArgs

        Private _bytesTransferred As Integer
        Private _totalBytesTransferred As Long
        Private _transferSize As Long
        Private _bytesPerSecond As Integer
        Private _elapsedTime As TimeSpan
        Private _percentComplete As Integer

        ''' <summary>
        ''' Constructor.
        ''' </summary>
        ''' <param name="bytesTransferred">The number of bytes transferred in the last transfer block.</param>
        ''' <param name="totalBytesTransferred">Total number of bytes transferred since transfer began.</param>
        ''' <param name="transferSize">Size of the data transfer.</param>
        ''' <param name="bytesPerSecond">The data transfer speed in bytes per second over the entire duration of the data transfer.</param>
        ''' <param name="elapsedTime">The time that has elapsed since the data transfer started.</param>
        ''' <param name="percentComplete">The percentage that the transfer has completed.</param>
        Public Sub New(bytesTransferred As Integer, totalBytesTransferred As Long, transferSize As Long, bytesPerSecond As Integer, elapsedTime As TimeSpan, percentComplete As Integer)
            _bytesTransferred = bytesTransferred
            _totalBytesTransferred = totalBytesTransferred
            _transferSize = transferSize
            _bytesPerSecond = bytesPerSecond
            _elapsedTime = elapsedTime
            _percentComplete = percentComplete
        End Sub

        ''' <summary>
        ''' The number of bytes transferred in the last transfer block.  
        ''' </summary>
        Public ReadOnly Property BytesTransferred() As Integer
            Get
                Return _bytesTransferred
            End Get
        End Property

        ''' <summary>
        ''' The total number of bytes transferred for a particular transfer event.
        ''' </summary>
        Public ReadOnly Property TotalBytesTransferred() As Long
            Get
                Return _totalBytesTransferred
            End Get
        End Property

        ''' <summary>
        ''' Gets the data transfer speed in bytes per second.
        ''' </summary>
        Public ReadOnly Property BytesPerSecond() As Integer
            Get
                Return _bytesPerSecond
            End Get
        End Property

        ''' <summary>
        ''' Gets the data transfer speed in Kilobytes per second.
        ''' </summary>
        Public ReadOnly Property KilobytesPerSecond() As Integer
            Get
                Return _bytesPerSecond \ 1024
            End Get
        End Property

        ''' <summary>
        ''' Gets the data transfer speed in Megabytes per second.
        ''' </summary>
        Public ReadOnly Property MegabytesPerSecond() As Integer
            Get
                Return _bytesPerSecond \ 1024 \ 1024
            End Get
        End Property

        ''' <summary>
        ''' Gets the data transfer speed in Gigabytes per second.
        ''' </summary>
        Public ReadOnly Property GigabytesPerSecond() As Integer
            Get
                Return _bytesPerSecond \ 1024 \ 1024 \ 1024
            End Get
        End Property

        ''' <summary>
        ''' Gets the time that has elapsed since the data transfer started.
        ''' </summary>
        Public ReadOnly Property ElapsedTime() As TimeSpan
            Get
                Return _elapsedTime
            End Get
        End Property

        ''' <summary>
        ''' Gets the percentage the transfer is complete if data is available.
        ''' </summary>
        ''' <remarks>
        ''' This data is not available for PutFile() stream transfers that do not support seeking.  This data
        ''' will not be accurately represented when zlib compression is enabled.  This data is not available
        ''' for non-file data transfer events.
        ''' </remarks>
        Public ReadOnly Property PercentComplete() As Integer
            Get
                Return _percentComplete
            End Get
        End Property

        ''' <summary>
        ''' Gets the size of the data transfer if data is available.
        ''' </summary>
        ''' <remarks>
        ''' This data is not available for PutFile() stream transfers that do not support seeking.  This data
        ''' will not be accurately represented when zlib compression is enabled.  This data is not available
        ''' for non-file data transfer events.
        ''' </remarks>
        Public ReadOnly Property TransferSize() As Long
            Get
                Return _transferSize
            End Get
        End Property

        ''' <summary>
        ''' The number of bytes remaining in the transfer.
        ''' </summary>
        ''' <remarks>
        ''' This data is not available for PutFile() stream transfers that do not support seeking.  This data
        ''' will not be accurately represented when zlib compression is enabled.  This data is not available
        ''' for non-file data transfer events.
        ''' </remarks>
        Public ReadOnly Property BytesRemaining() As Long
            Get
                If _transferSize < 0 Then
                    Return 0
                End If
                Return (_transferSize - _totalBytesTransferred)
            End Get
        End Property


        ''' <summary>
        ''' Gets the estimated time that remains for the data transfer.
        ''' </summary>
        ''' <remarks>
        ''' This data is not available for PutFile() stream transfers that do not support seeking.  This data
        ''' will not be accurately represented when zlib compression is enabled.  This data is not available
        ''' for non-file data transfer events.
        ''' </remarks>
        Public ReadOnly Property TimeRemaining() As TimeSpan
            Get
                If _transferSize < 0 Then
                    Return New TimeSpan()
                End If
                Dim sec As Integer = CInt(BytesRemaining \ _bytesPerSecond)
                Return New TimeSpan(0, 0, sec)
            End Get
        End Property

    End Class
End Namespace
